﻿using HuaWei;
using HuaWei.CommClass;
using HuaWei.Common;
using HuaWei.DAI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Runtime.InteropServices;

internal class Class32 : Class30, Interface1
{
    public bool imethod_0(string _str3, string _str4)
    {
        IDataAccess access = Class38.smethod();
        try
        {
            base.dataSet = access.GetDs(base.YfQclfhSo, _str3, _str4);
            if (base.dataSet != null)
            {
                if (_str3.Equals("GetAllData"))
                {
                    return this.method9(base.dataSet);
                }
                else if (_str3.Equals("GetUpdateData"))
                {
                    return this.YfQclfhSo(base.dataSet);
                }
                else if (_str3.Equals("GetXMJBXX"))
                {
                    return this.method7(base.dataSet);
                }
            }
        }
        catch (Exception exception)
        {
            Log.Write(exception.Message);
            return false;
        }
        return false;
    }

    public bool imethod_1([Optional, DefaultParameterValue(false)] bool _flag)
    {
        throw new NotImplementedException();
    }

    public bool imethod_2(SJLX sjlx)
    {
        throw new NotImplementedException();
    }

    public bool imethod_3(string _str3)
    {
        throw new NotImplementedException();
    }

    public bool imethod_4(string _str3)
    {
        throw new NotImplementedException();
    }

    public bool imethod_5(string _str3)
    {
        throw new NotImplementedException();
    }

    public bool imethod_6(DataSet dataSet1, DataSet dataSet2, bool _flag)
    {
        throw new NotImplementedException();
    }

    public void JvBxsoguG(DataSet dataSet1, DataSet dataSet2, string _str3)
    {
        base.GetEmpDt(base.YfQclfhSo, _str3);
        //if (_str3 == "BGL" || _str3 == "BGLQD")
        //{
        //base.CopyImportDataForBGLQD(dataSet1, dataSet2, _str3, "");
        //}
        //else
        //{
        //if (_str3 != "BGL" && _str3 != "BGLQD")
        //{
        base.CopyImportData(dataSet1, dataSet2, _str3, "");
        //}
        //}
    }

    public void CopyData(DataSet dataSet1, DataSet dataSet2, string _str3)
    {
        base.GetEmpDt(base.YfQclfhSo, _str3);
        foreach (DataRow dr in dataSet2.Tables[_str3].Rows)
        {
            DataRow[] drs = base.YfQclfhSo.Tables[_str3].Select("ID='" + dr["ID"] + "'");
            if (drs != null && drs.Length > 0)
            {
                continue;
            }
            base.YfQclfhSo.Tables[_str3].Rows.Add(dr.ItemArray);
        }

    }

    public void method10(DataTable dataTable, ArrayList arrayList)
    {
        foreach (DataRow row in dataTable.Rows)
        {
            row["tableName"].ToString();
            string str = row["RecId"].ToString();
            string str2 = string.Format("delete from {0} where id='{1}' and qcid={2}", str);
            arrayList.Add(str2);
        }
    }

    public ArrayList method11(DataSet dataSet1, ArrayList arrayList)
    {
        DataTable table = dataSet1.Tables["JGSCRZ"];
        DataTable table2 = dataSet1.Tables["REP_ZQZFZS"];
        if (table != null)
        {
            string str = "";
            string str2 = "";
            string where = string.Empty;
            foreach (DataRow row in table.Rows)
            {
                str = row["bdid"].ToString();
                str2 = row["qcid"].ToString();
                if ((table2 != null) && (table2.Select(string.Format("bdid='{0}' and qcid='{1}'", str, str2)).Length > 0))
                {
                    where += string.Format("(bdid='{0}' and qcid={1}) or ", str, str2);
                }
            }
            if (!string.IsNullOrEmpty(where))
            {
                where = where.Substring(0, where.Length - 3);
                string str3 = string.Format("delete from {0} where {1}", "REP_ZQZFZS", where);
                arrayList.Add(str3);
                str3 = string.Format("delete from {0} where {1}", "REP_ZQJKZF1", where);
                arrayList.Add(str3);
                str3 = string.Format("delete from {0} where {1}", "REP_ZQJKZF2", where);
                arrayList.Add(str3);
                //str3 = string.Format("delete from {0} where {1}", "REP_GCBG", where);
                //arrayList.Add(str3);
            }
        }
        return arrayList;
    }

    private void method12(DataTable dataTable, ArrayList arrayList)
    {
        string tableName = dataTable.TableName;
        string str2 = "";
        string str3 = DHelp.GetIdsDistinct(dataTable, "id", "");//DHelp.GetIds(dataTable, "id", "");
        string str4 = "";
        if (dataTable.Columns.Contains("sid"))
        {
            str2 = DHelp.GetIdsDistinct(dataTable, "sid", "");
        }
        if (!str3.Equals(""))
        {
            if (str2.Equals(""))
            {
                str4 = string.Format("delete from {0} where id in ({1})", tableName, str3);
            }
            else
            {
                str4 = string.Format("delete from {0} where id in ({1}) and sid in ({2})", tableName, str3, str2);
            }
            arrayList.Add(str4);
        }
    }


    private void DeleteData(DataTable dataTable)
    {
        string tableName = dataTable.TableName;
        string str2 = "";
        string str3 = DHelp.GetIdsDistinct(dataTable, "id", "");//DHelp.GetIds(dataTable, "id", "");
        string str4 = "";
        if (dataTable.Columns.Contains("sid"))
        {
            str2 = DHelp.GetIdsDistinct(dataTable, "sid", "");
        }
        if (!str3.Equals(""))
        {
            ArrayList arrayList = new ArrayList();
            if (str2.Equals(""))
            {
                str4 = string.Format("delete from {0} where id in ({1})", tableName, str3);
            }
            else
            {
                str4 = string.Format("delete from {0} where id in ({1}) and sid in ({2})", tableName, str3, str2);
            }
            arrayList.Add(str4);
            base.ida.OpenDatabase();
            base.ida.ExecuteNonQuery(arrayList, CommandType.Text);
            base.ida.CloseDatabase();
        }
    }

    private void DeleteDataForREPGCBG(DataTable dataTable)
    {
        string tableName = dataTable.TableName;
        string str3 = string.Empty;
        List<string> lstDeleteCondition = new List<string>();
        foreach (DataRow dr in dataTable.Rows)
        {
            string str = "(BDID ='" + dr["BDID"] + "' AND QCID ='" + dr["QCID"] + "')";
            if (!lstDeleteCondition.Contains(str))
            {
                lstDeleteCondition.Add(str);
                str3 += str + " or ";
            }
        }
        if (!str3.Equals(""))
        {
            str3 = str3.Substring(0, str3.Length - 4);
            ArrayList arrayList = new ArrayList();
            string str4 = string.Format("delete from {0} where {1}", tableName, str3);
            arrayList.Add(str4);
            base.ida.OpenDatabase();
            base.ida.ExecuteNonQuery(arrayList, CommandType.Text);
            base.ida.CloseDatabase();
        }
    }

    private ArrayList method13(DataSet dataSet1)
    {
        ArrayList list = new ArrayList();
        DataTable table = base.dataSet.Tables["JGSCRZ"];
        if (table != null)
        {
            string str = "";
            string str2 = "";
            string str3 = "";
            string tableName = "";
            foreach (DataRow row in table.Rows)
            {
                str = row["bdid"].ToString();
                str2 = row["jgid"].ToString();
                str3 = row["qcid"].ToString();
                foreach (TableInfo info in base.tableInfoList)
                {
                    tableName = info.TableName;
                    DataTable dt = base.dataSet.Tables[tableName + "2"];
                    if (dt != null)
                    {
                        string str5 = string.Format("delete from {0} where bdid='{1}' and qcid='{2}'", info.TableName, str, str3);
                        list.Add(str5);
                        str5 = string.Format("insert into {0} ({1}) select {1} from {0}2 where bdid='{2}' and qcid='{3}' and sid='{4}'", new object[] { tableName, DHelp.GetDtFieldNames(dt), str, str3, str2 });
                        list.Add(str5);
                    }
                }
            }
        }
        return list;
    }

    private bool method7(DataSet dataSet1)
    {
        base.YfQclfhSo = new DataSet();
        base.ida = DBHelp.IniIDA();
        string exeStr = "";
        DataTable table = dataSet1.Tables["XMJBXX"];
        if ((table != null) && (table.Rows.Count > 0))
        {
            this.JvBxsoguG(base.YfQclfhSo, dataSet1, "XMJBXX");
        }
        base.ida.OpenDatabase();
        try
        {
            base.ida.BeginTrans();
            exeStr = "delete from XMJBXX";
            base.ida.ExecuteNonQuery(exeStr, CommandType.Text);
            base.ida.Update(base.YfQclfhSo, true);
            exeStr = "delete from XMJBXXEX where id not in (select id from XMJBXX)";
            base.ida.ExecuteNonQuery(exeStr, CommandType.Text);
            exeStr = "delete from ZZJGXXEX where id in (select id from zzjgxx where xmid not in (select id from XMJBXX))";
            base.ida.ExecuteNonQuery(exeStr, CommandType.Text);
            exeStr = "delete from ZZJGXX where id in (select id from zzjgxx where xmid not in (select id from XMJBXX))";
            base.ida.ExecuteNonQuery(exeStr, CommandType.Text);
            exeStr = "delete from JLQD where xmid not in (select id from XMJBXX)";
            base.ida.ExecuteNonQuery(exeStr, CommandType.Text);
            exeStr = "delete from CLQD where xmid not in (select id from XMJBXX)";
            base.ida.ExecuteNonQuery(exeStr, CommandType.Text);
            exeStr = "insert into XMJBXXEX (id) select id from XMJBXX where id not in (select id from XMJBXXEX)";
            base.ida.ExecuteNonQuery(exeStr, CommandType.Text);
            base.ida.Commit();
        }
        catch (Exception exception)
        {
            Log.Write(exception.Message);
            base.ida.RollBack();
            return false;
        }
        return true;
    }

    private bool method8(string _str3)
    {
        return _str3.Equals("JGSCRZ");
    }

    public bool method9(DataSet dataSet1)
    {
        try
        {
            DataTable current;
            base.YfQclfhSo = new DataSet();
            base.ida = DBHelp.IniIDA();
            string tableName = null;
            ArrayList sqls = new ArrayList();
            IEnumerator enumerator = dataSet1.Tables.GetEnumerator();
            {
                while (enumerator.MoveNext())
                {
                    current = (DataTable)enumerator.Current;
                    if (current.Rows.Count > 0)
                    {
                        tableName = current.TableName;
                        this.JvBxsoguG(base.YfQclfhSo, dataSet1, tableName);
                    }
                }
            }
            List<TableInfo> list2 = SysDtManager.IniJLTableList();
            DataTable table2 = base.YfQclfhSo.Tables["xmqc"];
            string str2 = "";
            string str3 = "";
            string loginId = "";
            string str5 = "";
            string str6 = "";
            if (table2 != null)
            {
                DataTable table3 = base.YfQclfhSo.Tables["JGSCRZ"];
                foreach (DataRow row in table2.Rows)
                {
                    str2 = row["bdid"].ToString();
                    str3 = row["qcid"].ToString();
                    str6 = row["yzid"].ToString();
                    loginId = "";
                    if (row["zt"].Equals(1))
                    {
                        loginId = str6;
                    }
                    else if (table3.Select("bdid='" + str2 + "' and qcid='" + str3 + "' and jgid='" + GParams.LoginId + "'").Length > 0)
                    {
                        loginId = GParams.LoginId;
                        row["zt"] = 0;
                        row.EndEdit();
                    }
                    else
                    {
                        DataRow[] rowArray = table3.Select("bdid='" + str2 + "' and qcid='" + str3 + "' and sjid='" + GParams.LoginId + "'");
                        if (rowArray.Length > 0)
                        {
                            loginId = rowArray[0]["jgid"].ToString();
                        }
                    }
                    if (!loginId.Equals(""))
                    {
                        foreach (TableInfo info in list2)
                        {
                            tableName = info.TableName;
                            string str7 = "";
                            current = dataSet1.Tables[tableName + "2"];
                            foreach (DataColumn column in current.Columns)
                            {
                                if (!column.ColumnName.Equals("HVS"))
                                {
                                    if (!str7.Equals(""))
                                    {
                                        str7 = str7 + ",";
                                    }
                                    str7 = str7 + column.ColumnName;
                                }
                            }
                            if (sqls.Count == 367)
                            {

                            }
                            str5 = string.Format("insert into {0} ({1}) select {1} from {0}2 where bdid='{2}' and qcid='{3}' and sid='{4}'", new object[] { tableName, str7, str2, str3, loginId });
                            sqls.Add(str5);
                        }
                    }
                }
            }
            base.ida.OpenDatabase();
            base.ida.BeginTrans();
            base.ida.Update(base.YfQclfhSo, true);
            base.ida.Commit();
            base.ida.ExecuteNonQuery(sqls, CommandType.Text);
        }
        catch (Exception)
        {
            base.ida.RollBack();
            return false;
        }
        return true;
    }

    public bool YfQclfhSo(DataSet dataSet1)
    {
        base.YfQclfhSo = new DataSet();
        base.ida = DBHelp.IniIDA();
        string tableName = null;
        ArrayList arrayList = new ArrayList();
        foreach (DataTable table in dataSet1.Tables)
        {
            tableName = table.TableName;
            if (tableName.Equals("DelInfo"))
            {
                this.method10(table, arrayList);
            }
            //else if (tableName.Equals("REP_GCBG"))
            //{
            //    arrayList.Add("delete from REP_GCBG");
            //}
            else
            {
                if (!this.method8(tableName) && (table.Rows.Count > 0))
                {
                    if (tableName.Equals("ZZJGXX") || tableName.Equals("ZZJGXXEX"))
                    {
                        this.method12(table, arrayList);
                    }
                    else if (tableName.Equals("REP_GCBG"))
                    {
                        DeleteDataForREPGCBG(table);
                    }
                    else
                    {
                        DeleteData(table);
                    }
                    if (tableName.Equals("XMQC"))
                    {
                        CopyData(base.YfQclfhSo, dataSet1, tableName);
                    }
                    else
                    {
                        this.JvBxsoguG(base.YfQclfhSo, dataSet1, tableName);
                    }
                }
            }
        }
        ArrayList sqls = this.method13(dataSet1);
        this.method11(dataSet1, arrayList);
        base.ida.OpenDatabase();
        try
        {
            base.ida.BeginTrans();
            base.ida.ExecuteNonQuery(arrayList, CommandType.Text);
            base.ida.Update(base.YfQclfhSo, true);
            base.ida.ExecuteNonQuery(sqls, CommandType.Text);
            base.ida.Commit();
        }
        catch (Exception)
        {
            base.ida.RollBack();
            return false;
        }
        return true;
    }
}

